<?php

namespace app\common\model;




class Vote extends BaseModel
{
    protected $updateTime = false;

    public function user(){
        return $this->belongsTo('User','user_id','id')->field('id,nickname,avatar,bio,education');
    }

    public function toUser(){
        return $this->belongsTo('User','to_user_id','id')->field('id,nickname,avatar,bio,education');
    }

    public static function getList($type,$userId,$page=1,$limit=''){
        if(empty($limit)){
            $limit = config('paginate.list_rows');
        }
        if($type == 1){
            return self::with('user,toUser')->where('user_id',$userId)->page($page,$limit)->order('created_at','desc')->select();
        }
        return self::with('user,toUser')->where('to_user_id',$userId)->page($page,$limit)->order('created_at','desc')->select();
    }
}
